#include "signal.h"
#include "engine.h"

using namespace lt;


signal::signal(sigid_t id, engine& engine):_id(id), _engine(engine)
{
}

signal::~signal()
{
	
}

void signal::init(subscriber& suber)
{
	this->on_init(suber);
}

void signal::destory(unsubscriber& unsubr)
{
	this->on_destory(unsubr);
}

void signal::subscrib_signal(signal_handler* hdl)
{
	auto it = _all_handler.find(hdl);
	if(it == _all_handler.end())
	{
		_all_handler.insert(hdl);
	}
}
void signal::unsubscrib_signal(signal_handler* hdl)
{
	auto it = _all_handler.find(hdl);
	if (it != _all_handler.end())
	{
		_all_handler.erase(it);
	}
}

void signal::trigger(const code_t& code, action_type type)
{
	for (auto& it : _all_handler)
	{
		it->on_signal(_id, code, type);
	}
}
